package reduce.fz.com.reduce.service;

import android.content.Context;

import com.alibaba.fastjson.TypeReference;

import java.util.HashMap;

import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.abstracts.AbResponseListener3;
import reduce.fz.com.reduce.abstracts.AbResponseListener;
import reduce.fz.com.reduce.bean.User;
import reduce.fz.com.reduce.bean.result.Result;
import reduce.fz.com.reduce.util.ApiUtil;
import reduce.fz.com.reduce.util.HttpUtils;

/**
 * Created by qingshengzheng on 15/7/30.
 */
public class UserService {
    private Context context;

    public UserService(Context context) {
        this.context = context;
    }

    public void resetPass(String mobile, String vcode, AbResponseListener<HashMap<String, Object>> listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", mobile);
        params.put("vcode", vcode);
        String url = ApiUtil.getApi(context, R.array.api_account_bind);
        url = ApiUtil.parseUrlParams(url, params);
        HttpUtils.get(url, listener);
    }

    public void loadBanners(AbResponseListener listener)
    {
        String url=ApiUtil.getApi(context,R.array.api_load_banners);
        HttpUtils.get(url,listener);
    }
    public void socialBind(User user,AbResponseListener listener)
    {
        String url=ApiUtil.getApi(context,R.array.api_social_bind);
        HttpUtils.jsonPost(url, user, listener);
    }


    public void register(User user, AbResponseListener<User> listener) {
        String url = ApiUtil.getApi(context, R.array.api_user_register);
        HttpUtils.jsonPost(url, user, listener);
    }

    public void userpraise(Long uid,Boolean isPraise,AbResponseListener listener)
    {
        String url=ApiUtil.getApi(context,R.array.api_card_praise,uid,isPraise);
        HttpUtils.get(url,listener);
    }



    public void modifyPassword(String mobile, String password, String oldPassword, AbResponseListener<User> listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", mobile);
        params.put("password", password);
        params.put("oldpassword", oldPassword);
        String url = ApiUtil.getApi(context, R.array.api_account_bind);
        HttpUtils.post(url, params, listener);
    }

    public void resetPassword(String mobile, String password,AbResponseListener listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", mobile);
        params.put("password", password);
        String url = ApiUtil.getApi(context, R.array.api_reset_password);
        HttpUtils.post(url, params, listener);
    }

    public void sendVcode(String mobile, int biztype, AbResponseListener listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", mobile);
        params.put("biztype", biztype);
        String url = ApiUtil.getApi(context, R.array.api_send_vcode);
        HttpUtils.post(url, params, listener);
    }

    public void modifyUser(User user, AbResponseListener listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", user.mobile);
        params.put("nickname", user.nickname);
        String url = ApiUtil.getApi(context, R.array.api_account_bind);
        HttpUtils.post(url, params, listener);
    }
    public void loginUser(User user, AbResponseListener<User> listener) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("mobile", user.mobile);
        params.put("password", user.password);
        String url = ApiUtil.getApi(context, R.array.api_user_login);
        url=ApiUtil.parseUrlParams(url,params);
        HttpUtils.get(url, listener);
    }
    public void isUserExist(String mobile,AbResponseListener listener)
    {
        String url=ApiUtil.getApi(context,R.array.api_isuser_exists,mobile);
        HttpUtils.get(url,listener);
    }
    public void getUser(Long uid,AbResponseListener listener)
    {
        String url=ApiUtil.getApi(context,R.array.api_get_user,uid);
        HttpUtils.get(url,listener);

    }



    public void follow(Long toUid,Boolean follow,AbResponseListener listener)
    {
         int type=1;
        if(follow) type=1;else type=0;
        String url=ApiUtil.getApi(context,R.array.api_user_follow,toUid,type);
        HttpUtils.get(url,listener);
    }




}
